<template>
  <div>
    <el-card
      shadow="hover"
      :body-style="{ height: state.height, padding: state.padding }"
    >
      <template #header v-if="state.title">
        <img v-if="state.img" :src="state.img" class="img" />
        <span class="title">{{ state.title }}</span>
        <el-tag
          style="position: relative; float: right"
          size="small"
          v-if="state.unit"
        >
          {{ state.unit }}
        </el-tag>
      </template>
      <slot name="title"></slot>
      <slot></slot>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { defineProps, reactive, onMounted } from "vue";

const props = defineProps({
  title: {
    type: String,
    default: "",
  },
  type: {
    type: Boolean,
    default: false,
  },
  height: {
    type: String,
    default: "",
  },
  padding: {
    type: String,
    default: "10px",
  },
  unit: {
    type: String,
    default: "",
  },
  img: {
    type: String,
    default: "",
  },
});
const state = reactive({
  img: "",
  title: "",
  unit: "",
  height: "",
  padding: "",
});
const init = () => {
  state.title = props.title;
  state.unit = props.unit;
  state.height = props.height;
  state.padding = props.padding;
  if (props.img) {
    state.img = props.img;
    // state.img = new URL(props.img, import.meta.url).href
  }
};

onMounted(() => {
  init();
});
</script>

<style lang="scss" scoped>
:deep(.el-card) {
  border-radius: 10px;
}

:deep(.el-card__header) {
  font-weight: 600;
  padding: 10px 10px 0 10px !important;
  display: flex;
  font-size: 14px !important;
  align-items: center;
  border-bottom: none;
  color: rgb(95, 89, 89);

  .img {
    width: 25px;
    height: 25px;
    margin-right: 4px;
  }
}
</style>
